<?php /** @noinspection ALL */

//资金流水

namespace app\admin\controller;

use think\facade\Db;

class MoneyLog {

	function show($page=1,$pageSize=10){
		$input=input();

		$userinfo=Pubilc::check_jwt($input['token']);

		if(!$userinfo)return json(['code' => 0,'msg'=>'请重新登录']);

		$id=$userinfo->userId;

		$type=$userinfo->type;

		$condition = ' and 1=1';

		if (!empty($input['userinfo'])) {
			$condition .= " and (u.nick_name like '%{$input['userinfo']}%' or u.tel like '%{$input['userinfo']}%' or u.real_name like '%{$input['userinfo']}%' ) ";
		}

		if($type==2){//代理

			$List = Db::query("select u.nick_name,u.tel,u.real_name,money_log.*,FROM_UNIXTIME(money_log.add_time,'%Y-%m-%d %H:%i:%s')  as add_time from money_log join system_user as u on u.id = money_log.uid where 1".$condition." and u.agent_id='{$id}'  order by money_log.id desc limit ".(($page-1)*$pageSize).",$pageSize");

			$total_num = Db::query("select count(money_log.id) as sum from money_log join system_user as u on u.id = money_log.uid where 1".$condition." and u.agent_id='{$id}' ");

		}else{
			$List = Db::query("select u.nick_name,u.tel,u.real_name,money_log.*,FROM_UNIXTIME(money_log.add_time,'%Y-%m-%d %H:%i:%s')  as add_time from money_log join system_user as u on u.id = money_log.uid where 1".$condition." order by money_log.id desc limit ".(($page-1)*$pageSize).",$pageSize");

			$total_num = Db::query("select count(money_log.id) as sum from money_log join system_user as u on u.id = money_log.uid where 1".$condition);
		}

		return json(['code' => 1, 'data' => $List,'total_num'=>$total_num[0]['sum']]);
	}

}